package  net.libra.ui.controls
{
	import flash.events.FocusEvent;
	import flash.text.TextField;

	public class FocusInputControl
	{
		protected var textField:TextField;
		protected var focusInColor:uint;
		protected var focusOutColor:uint;
		protected var focusOutText:String;
		
		public function FocusInputControl(textField:TextField,focusInColor:uint,focusOutColor:uint,focusOutText:String)
		{
			this.textField = textField;
			this.focusInColor = focusInColor;
			this.focusOutColor = focusOutColor;
			this.focusOutText = focusOutText||"";
			
			this.textField.addEventListener(FocusEvent.FOCUS_IN,focus);
			this.textField.addEventListener(FocusEvent.FOCUS_OUT,focus);
			checkFocus();
		}
		
		protected function checkFocus():void
		{
			if(textField.stage && textField.stage.focus == textField)
			{
				textField.textColor = focusInColor;
				if(textField.text == focusOutText)
				{
					textField.text = "";
				}else
				{
					textField.setSelection(0,0xFFFFFFFF);
				}
			}else
			{
				if(!textField.text)
				{
					textField.text = focusOutText;
					textField.textColor = focusOutColor;
				}else
				{
					
				}
			}
		}
		
		protected function focus(event:FocusEvent):void
		{
			if(event.type == FocusEvent.FOCUS_IN)
			{
				textField.textColor = focusInColor;
				if(textField.text == focusOutText)
				{
					textField.text = "";
				}else
				{
					textField.setSelection(0,0xFFFFFFFF);
				}
			}else
			{
				//内容为空
				if(!textField.text)
				{
					textField.text = focusOutText;
					textField.textColor = focusOutColor;
				}else
				{
					
				}
			}
		}
	}
}